#!/bin/bash

#1.编译打出 fat jar
mvn clean package -f ./pom.xml -s ./settings.xml

#2.转移到docker工作目录
mkdir ./docker
mv ./target/*.jar ./docker/springboot-demo.jar
mv ./Dockerfile ./docker

#3.构建镜像
# shellcheck disable=SC2164
cd ./docker
docker build -t springboot-demo .

#4.停止上一个镜像
# shellcheck disable=SC2155
declare s=$(docker ps -all |grep springboot-demo)
echo "$s"
# shellcheck disable=SC2155
declare re=$(echo "$s"|awk '{print $1}')
echo "$re"
docker stop "$re"

#5.部署新镜像
docker run -dp 8080:8080 springboot-demo

#.健康检查
docker ps -all |grep springboot-demo
curl -X POST -v http://127.0.0.1:8080/demo/hello/world